package com.liuliu.controller.zua;

import com.liuliu.common.annotation.Log;
import com.liuliu.common.core.controller.BaseController;
import com.liuliu.common.core.domain.AjaxResult;
import com.liuliu.common.core.page.TableDataInfo;
import com.liuliu.common.enums.BusinessType;
import com.liuliu.common.utils.poi.ExcelUtil;
import com.liuliu.zua.domain.ZuaLecture;
import com.liuliu.zua.service.IZuaLectureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 宣讲会Controller
 * 
 * @author ruoyi
 * @date 2021-03-22
 */
@RestController
@RequestMapping("/zua/lecture")
public class ZuaLectureController extends BaseController
{
    @Autowired
    private IZuaLectureService zuaLectureService;

    /**
     * 查询宣讲会列表
     */
    @PreAuthorize("@ss.hasPermi('zua:lecture:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZuaLecture zuaLecture)
    {
        startPage();
        List<ZuaLecture> list = zuaLectureService.selectZuaLectureList(zuaLecture);
        return getDataTable(list);
    }

    /**
     * 导出宣讲会列表
     */
    @PreAuthorize("@ss.hasPermi('zua:lecture:export')")
    @Log(title = "宣讲会", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZuaLecture zuaLecture)
    {
        List<ZuaLecture> list = zuaLectureService.selectZuaLectureList(zuaLecture);
        ExcelUtil<ZuaLecture> util = new ExcelUtil<ZuaLecture>(ZuaLecture.class);
        return util.exportExcel(list, "lecture");
    }

    /**
     * 获取宣讲会详细信息
     */
    @PreAuthorize("@ss.hasPermi('zua:lecture:query')")
    @GetMapping(value = "/{lectureId}")
    public AjaxResult getInfo(@PathVariable("lectureId") Long lectureId)
    {
        return AjaxResult.success(zuaLectureService.selectZuaLectureById(lectureId));
    }

    /**
     * 新增宣讲会
     */
    @PreAuthorize("@ss.hasPermi('zua:lecture:add')")
    @Log(title = "宣讲会", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZuaLecture zuaLecture)
    {
        return toAjax(zuaLectureService.insertZuaLecture(zuaLecture));
    }

    /**
     * 修改宣讲会
     */
    @PreAuthorize("@ss.hasPermi('zua:lecture:edit')")
    @Log(title = "宣讲会", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZuaLecture zuaLecture)
    {
//        System.out.println(zuaLecture);
        return toAjax(zuaLectureService.updateZuaLecture(zuaLecture));
    }

    /**
     * 删除宣讲会
     */
    @PreAuthorize("@ss.hasPermi('zua:lecture:remove')")
    @Log(title = "宣讲会", businessType = BusinessType.DELETE)
	@DeleteMapping("/{lectureIds}")
    public AjaxResult remove(@PathVariable Long[] lectureIds)
    {
        return toAjax(zuaLectureService.deleteZuaLectureByIds(lectureIds));
    }
}
